<!DOCTYPE html>
<html lang="en">

<head>
  {include file="common/meta" /}
</head>

<body>
  <div class="x-body">
    <!-- 搜索 -->
    <div class="layui-row">
      <form method="get" class="layui-form layui-col-md12 x-so">
        <input class="layui-input" placeholder="开始日" name="start" id="start" value="{$start}" />

        <input class="layui-input" placeholder="截止日" name="end" id="end" value="{$end}" />

        <input type="text" name="keywords" placeholder="" autocomplete="off" value="{$keywords}" class="layui-input">

        <button class="layui-btn">
          <i class="layui-icon">&#xe615;</i>
        </button>

      </form>
    </div>


    <xblock>
      <button class="layui-btn layui-btn-normal" onclick="examAll()">
        <i class="layui-icon"></i>批量审核通过
      </button>

      <span class="x-right" style="line-height:40px">
        共有数据：{$rechargeCount} 条
      </span>
    </xblock>

    <table class="layui-table">
      <thead>
        <tr>
          <th>
            <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i>
            </div>
          </th>
          <th>昵称</th>
          <th>审核人</th>
          <th>充值金额</th>
          <th>充值时间</th>
          <th>截图</th>
          <th>备注</th>
          <th>状态</th>
      </thead>

      <tbody>
        {foreach $rechargeList as $item}
        <tr>
          <td>
            {if condition="$item.status == '0'"}
            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="{$item.id}">
              <i class="layui-icon">&#xe605;</i>
            </div>
            {else/}
            <div class="layui-unselect layui-btn-disabled" lay-skin="primary" data-id="{$item.id}">
              <i class="layui-icon">&#xe605;</i>
            </div>
            {/if}
          </td>
          <td><a href="{:url('admin/record/index',['id' => $item.id])}">{$item.user.nickname}</a></td>
          <td>
            {if condition="$item.adminid"}
            {$item.admin.nickname}
            {else/}
            <span>无</span>
            {/if}
          </td>
          <td>{$item.point}</td>
          <td>{$item.createtime}</td>
          <td>{$item.gallery}</td>
          <td>{$item.content}</td>
          <td style="text-align: center;">
            {if condition="$item.status == '0'"}
            <button class="layui-btn layui-btn-warm" onclick="examOne(`{$item.id}`)">
              未审核
            </button>
            {elseif condition="$item.status == '1'"}
            <button class="layui-btn">
              已审核
            </button>
            {elseif condition="$item.status == '2'"}
            <button class="layui-btn layui-btn-danger">
              未通过
            </button>
            {/if}
          </td>
        </tr>
        {/foreach}
      </tbody>
    </table>

    <div class="page">
      {$rechargeStr}
    </div>

</body>

<script>
  layui.use('laydate', function () {
    var laydate = layui.laydate;

    //执行一个laydate实例
    laydate.render({
      elem: '#start' //指定元素
    });

    //执行一个laydate实例
    laydate.render({
      elem: '#end' //指定元素
    });

  })

  function examOne(id) {
    layer.open({
      title: "审核",
      area: ['450px', 'auto'],
      content: ' <div class="row" style="width: 420px;  margin-left:7px; margin-top:10px;">'
        + '<label>备注：</label>'
        + '<textarea id="content" cols="20" rows="3"></textarea>'
        + '</div>'

      , btn: ['通过', '不通过']
      , yes: function (index, layero) {
        var content = document.querySelector("#content").value;
        var status = '1'
        let data = {
          id: id,
          content: content,
          status: status,

        }

        exam(data)
        layer.close(index);
      }
      , btn2: function (index, layero) {
        var content = document.querySelector("#content").value;
        var status = '1';

        let data = {
          id: id,
          content: content,
          status: status,
        }
        exam(data)

      }
    })
  }

  // });
  // // 单个删除
  // function delOne(id) {
  //   layer.confirm('确认要删除吗？', function (index) {
  //     layer.close(index);
  //     del(id);
  //   })
  // }

  // 批量
  function examAll() {
    var ids = tableCheck.getData()
    layer.confirm('确认要审核通过吗？', function (index) {
      //将数组转换为字符串
      var data = ids.join(',');
      var obj = {
        id: data,
        content: "批量审核通过",
        status: '1',
      }
      console.log(obj);
      exam(obj);

    })
  }

  // 调用方法
  function exam(data) {
    // 序列化 将对象转换为参数形式
    var params = {
      ids: data.id,
      content: data.content,
      status: data.status,
    }

    // params = $.param(params);

    console.log(params);

    $.ajax({
      type: "POST",
      url: `{:url('admin/recharge/exam')}`,
      data: params,
      dataType: "json",
      success: function (data) {
        if (data.code == '1') {
          // 成功
          layer.msg(data.msg, {
            icon: 1,
            time: 2000,
          }, function () {
            // 收藏成功刷新界面
            location.reload();
          })
        } else {
          // 失败
          layer.msg(data.msg);
        }
      }
    })
  }
</script>

</html>